// 构建分析脚本
import { build } from 'vite'
import { visualizer } from 'rollup-plugin-visualizer'
import path from 'path'

async function buildWithAnalyze() {
  try {
    console.log('🚀 开始构建并分析...')
    
    await build({
      plugins: [
        visualizer({
          filename: 'dist/stats.html',
          open: true,
          gzipSize: true,
          brotliSize: true,
        })
      ]
    })
    
    console.log('✅ 构建完成！')
    console.log('📊 分析报告已生成：dist/stats.html')
    
  } catch (error) {
    console.error('❌ 构建失败：', error)
    process.exit(1)
  }
}

buildWithAnalyze()
